package be.quadreg.dojo.model.entity;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import be.quadreg.dojo.persistence.GenericDAO;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Subclass;

@Subclass
public class BeltHistoryMemberAttribute extends MemberAttribute {
	public static enum Belt {
		WHITE, YELLOW, ORANGE, GREEN, BLUE, BROWN, BLACK
	};

	public static class BeltHistory {
		@Id private Long id;
		private Date date;
		private Belt belt;

		public BeltHistory() {
		}
		
		public BeltHistory(Date date, Belt belt) {
			super();
			this.date = date;
			this.belt = belt;
		}

		public Date getDate() {
			return date;
		}

		public void setDate(Date date) {
			this.date = date;
		}

		public Belt getBelt() {
			return belt;
		}

		public void setBelt(Belt belt) {
			this.belt = belt;
		}

	}

	private Set<Key<BeltHistory>> beltHistoryKeys;

	public BeltHistoryMemberAttribute() {
		beltHistoryKeys = new HashSet<Key<BeltHistory>>();
	}

	@OneToMany(cascade = CascadeType.ALL)
	public Collection<BeltHistory> getBeltHistory() {
		return GenericDAO.getInstance().getBeltHistory( beltHistoryKeys );
	}


	public void setBelt(Date date, Belt belt) {
		BeltHistory bh = new BeltHistory(date, belt);
		Key<BeltHistory> key = GenericDAO.getInstance().persistBeltHistory( bh );
		beltHistoryKeys.add( key );
	}

	@Override
	public String toString() {
		return "BeltHistoryMemberAttribute [beltHistory=" + getBeltHistory() + "]";
	}
	
	

}
